package com.peng.community.util;

import com.peng.community.entity.User;
import org.springframework.stereotype.Component;

@Component
//利用ThreadLocal代替session存储用户信息
//默认每个请求由一个线程独立完成
public class HostHolder {
    ThreadLocal<User> userThreadLocal = new ThreadLocal<>();

    public  void setUser(User user) {
        userThreadLocal.set(user);
    }

    public  User getUser() {
        return userThreadLocal.get();
    }

    public  void removeUser() {
        userThreadLocal.remove();
    }
}
